home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / UI / UI_DIAL.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  9KB  |  357 lines

  1. /****************************************************************
  2.  
  3.     ui_dial.c       Dialog-box and alarm-box routines for
  4.             The Bywater Graphical User Interface
  5.  
  6.             Copyright (c) 1991, Ted A. Campbell
  7.  
  8.             Bywater Software
  9.             P. O. Box 4023 
  10.             Duke Station 
  11.             Durham, NC  27706
  12.  
  13.             email: tcamp@hercules.acpub.duke.edu
  14.  
  15.     Copyright and Permissions Information:
  16.  
  17.     All U.S. and international copyrights are claimed by the
  18.     author. The author grants permission to use this code
  19.     and software based on it under the following conditions:
  20.     (a) in general, the code and software based upon it may be 
  21.     used by individuals and by non-profit organizations; (b) it
  22.     may also be utilized by governmental agencies in any country,
  23.     with the exception of military agencies; (c) the code and/or
  24.     software based upon it may not be sold for a profit without
  25.     an explicit and specific permission from the author, except
  26.     that a minimal fee may be charged for media on which it is
  27.     copied, and for copying and handling; (d) the code must be 
  28.     distributed in the form in which it has been released by the
  29.     author; and (e) the code and software based upon it may not 
  30.     be used for illegal activities. 
  31.  
  32. ****************************************************************/
  33.  
  34. #include "stdio.h"
  35. #include "gr.h"
  36. #include "ui.h"
  37.  
  38. ui_dial( x1, y1, x2, y2, background, foreground, marker_color, shadow,
  39.    title, text, prompt, buffer, i_window )
  40.    int x1, y1, x2, y2, background, foreground, shadow, marker_color;
  41.    char *title, *text, *prompt, *buffer;
  42.    struct uiwindow **i_window;
  43.    {
  44.    static struct uiwindow *window;
  45.    register int x, y;
  46.  
  47.    /* Draw the box */
  48.  
  49.    if ( *i_window == NULL )
  50.       {
  51.       window = *i_window = ui_window( x1, y1, x2, y2, TRUE, background,
  52.      foreground, title, TRUE, BLACK,
  53.      shadow, BLACK, background, SOLID, BUT_CLOSE );
  54.       }
  55.    else
  56.       {
  57.       window = *i_window;
  58.       ui_rewindow( window, title );
  59.       }
  60.  
  61.    /* Write the text string to the box */
  62.  
  63.    ui_text( window->u_x1 + gr_strlen( "   " ),
  64.       window->u_y1 + ( ui_grwind->fysize * 3 ),
  65.       window->u_x2, window->u_y2, 20, background, foreground, 
  66.       text );
  67.  
  68.    /* Set array coordinates for prompt and entry string */
  69.  
  70.    x = window->u_x1 + gr_strlen( "======" );
  71.    y = window->u_y1 + ( ui_grwind->fysize * 2 );
  72.  
  73.    /* Display a marker */ 
  74.  
  75.    gr_circle( ui_screen, x,
  76.       y + ui_grwind->fysize / 2,
  77.       ui_grwind->fysize / 4, marker_color, SOLID );
  78.    x += ui_grwind->fysize * 2;
  79.  
  80.    /* Display the prompt string */
  81.  
  82.    ui_str( x, y, window->u_x2,
  83.       background, foreground, prompt );
  84.    x += gr_strlen( prompt );
  85.  
  86.    /* Get the string from the box */
  87.  
  88.    ui_gets( window, x, y, 64, buffer,
  89.       TRUE, foreground, background );
  90.  
  91.    }
  92.  
  93. ui_yn( x1, y1, x2, y2, background, foreground, marker_color, shadow,
  94.    text, mes0, mes1, i_window )
  95.    int x1, y1, x2, y2, background, foreground, shadow, marker_color;
  96.    char *text, *mes0, *mes1;
  97.    struct uiwindow **i_window;
  98.    {
  99.    static struct uiwindow *window;
  100.    register int x, y;
  101.    int y_x1, y_y1, y_x2, y_y2;
  102.    int n_x1, n_y1, n_x2, n_y2;
  103.    int carry_on, mo_xsrc, mo_ysrc, test, key;
  104.    static int x_pos, y_pos, b_stat;
  105.    
  106.    /* Draw the box */
  107.  
  108.    if ( *i_window == NULL )
  109.       {
  110.       window = *i_window = ui_window( x1, y1, x2, y2, FALSE, background,
  111.          foreground, "", 1, 0, 
  112.      shadow, 0, background, 1, 0 );
  113.       }
  114.    else
  115.       {
  116.       window = *i_window;
  117.       ui_rewindow( window, "" );
  118.       }
  119.  
  120.    /* Write the text string to the box */
  121.  
  122.    ui_text( window->u_x1 + gr_strlen( "   " ),
  123.       window->u_y1 + ( ui_grwind->fysize * 3 ),
  124.       window->u_x2, window->u_y2, 20, background, foreground, 
  125.       text );
  126.  
  127.    /* Set array coordinates for capsules */
  128.  
  129.    x = window->u_x1 + (( window->u_x2 - window->u_x1 ) / 3 );
  130.    y = window->u_y1 + ( ui_grwind->fysize * 2 );
  131.  
  132.    y_x1 = x - ( gr_strlen( mes1 ) / 2 );
  133.    y_x2 = x + ( gr_strlen( mes1 ) / 2 );
  134.  
  135.    n_y1 = y_y1 = y;
  136.    n_y2 = y_y2 = y + (( ui_grwind->fysize * 3 ) / 2 );
  137.  
  138.    x = x + (( window->u_x2 - window->u_x1 ) / 3 );
  139.    n_x1 = x - ( gr_strlen( mes0 ) / 2 );
  140.    n_x2 = x + ( gr_strlen( mes0 ) / 2 );
  141.  
  142.    /* show capsules and their text */
  143.  
  144.    uid_capsule( y_x1, y_y1, y_x2, y_y2, BLACK, SOLID );
  145.    uid_capsule( n_x1, n_y1, n_x2, n_y2, BLACK, SOLID );
  146.  
  147.    gr_text( ui_screen, y_x1,
  148.       y_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
  149.       mes1, background, foreground );
  150.  
  151.    gr_text( ui_screen, n_x1,
  152.       n_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
  153.       mes0, background, foreground );
  154.  
  155.    /* loop for response */
  156.  
  157.    carry_on = TRUE;
  158.    while ( carry_on == TRUE )
  159.       {
  160.       if ( kb_rxstat() == TRUE )
  161.          {
  162.          key = kb_rx();
  163.  
  164.          switch( key )
  165.             {
  166.             case 'Y':
  167.             case 'y':
  168.                return TRUE;
  169.                break;
  170.             case 'N':
  171.             case 'n':
  172.                return FALSE;
  173.                break;
  174.             default:
  175.                break;
  176.             }
  177.          }
  178.  
  179.       else if ( gr_ismouse == TRUE )
  180.          {
  181.  
  182.          if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
  183.             == TRUE )
  184.             {
  185.             key = 0;
  186.             test = TRUE;
  187.             gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  188.             mo_xsrc = x_pos;
  189.             mo_ysrc = y_pos;
  190.             gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  191.             }
  192.          
  193.          if ( test == TRUE )
  194.             {
  195.         if ( uil_bounds( x_pos, y_pos, y_x1, y_y1, y_x2, y_y2 ) == TRUE )
  196.                {
  197.                return TRUE;
  198.                }
  199.         else if ( uil_bounds( x_pos, y_pos, n_x1, n_y1, n_x2, n_y2 ) == TRUE )
  200.                {
  201.                return FALSE;
  202.                }
  203.             }
  204.  
  205.          test = FALSE;
  206.          }
  207.  
  208.       else
  209.          {
  210.      ui_poll();
  211.          }
  212.       }
  213.  
  214.    }
  215.  
  216. ui_alarm( x1, y1, x2, y2, background, foreground, marker_color, shadow,
  217.    text, prompt, i_window )
  218.    int x1, y1, x2, y2, background, foreground, shadow, marker_color;
  219.    char *text, *prompt;
  220.    struct uiwindow **i_window;
  221.    {
  222.    static struct uiwindow *window;
  223.    int y_x1, y_y1, y_x2, y_y2;
  224.    register int x, y;
  225.    int carry_on, mo_xsrc, mo_ysrc, test, key;
  226.    static int x_pos, y_pos, b_stat;
  227.  
  228.    /* Draw the box */
  229.  
  230.    if ( *i_window == NULL )
  231.       {
  232.       *i_window = window = ui_window( x1, y1, x2, y2, FALSE, background,
  233.          foreground, "", 1, 0, 
  234.      shadow, 0, background, 1, 0 );
  235.       }
  236.    else
  237.       {
  238.       window = *i_window;
  239.       ui_rewindow( window, "" );
  240.       }
  241.  
  242.    /* Write the text string to the box */
  243.  
  244.    ui_text( window->u_x1 + gr_strlen( "   " ),
  245.       window->u_y1 + ( ui_grwind->fysize * 3 ),
  246.       window->u_x2, window->u_y2, 20, background, foreground, 
  247.       text );
  248.  
  249.    /* Set array coordinates for capsules */
  250.  
  251.    x = window->u_x1 + ((( window->u_x2 - window->u_x1 ) / 3 ) * 2 );
  252.    y = window->u_y1 + ( ui_grwind->fysize * 2 );
  253.  
  254.    y_x1 = x - ( gr_strlen( prompt ) / 2 );
  255.    y_x2 = x + ( gr_strlen( prompt ) / 2 );
  256.  
  257.    y_y1 = y;
  258.    y_y2 = y + (( ui_grwind->fysize * 3 ) / 2 );
  259.  
  260.    /* show capsule and text */
  261.  
  262.    uid_capsule( y_x1, y_y1, y_x2, y_y2, BLACK, SOLID );
  263.  
  264.    gr_text( ui_screen, y_x1,
  265.       y_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
  266.       prompt, background, foreground );
  267.  
  268.    /* loop for response */
  269.  
  270.    carry_on = TRUE;
  271.    while ( carry_on == TRUE )
  272.       {
  273.       if ( kb_rxstat() == TRUE )
  274.          {
  275.          key = kb_rx();
  276.          return key;
  277.          }
  278.  
  279.       else if ( gr_ismouse == TRUE )
  280.          {
  281.  
  282.          if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
  283.             == TRUE )
  284.             {
  285.             key = 0;
  286.             test = TRUE;
  287.             gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  288.             mo_xsrc = x_pos;
  289.             mo_ysrc = y_pos;
  290.             gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  291.             }
  292.          
  293.          if ( test == TRUE )
  294.             {
  295.         if ( uil_bounds( x_pos, y_pos, y_x1, y_y1, y_x2, y_y2 ) == TRUE )
  296.                {
  297.                return TRUE;
  298.                }
  299.             }
  300.  
  301.          test = FALSE;
  302.          }
  303.  
  304.       else
  305.          {
  306.      ui_poll();
  307.          }
  308.       }
  309.  
  310.    }
  311.  
  312. ui_disp( x1, y1, x2, y2, background, foreground, shadow, title, text,
  313.    i_window )
  314.    int x1, y1, x2, y2, background, foreground, shadow;
  315.    char *title, *text;
  316.    struct uiwindow **i_window;
  317.    {
  318.    static struct uiwindow *window;
  319.  
  320.    /* Draw the box */
  321.  
  322.    if ( *i_window == 0 )
  323.       {
  324.       *i_window = window = ui_window( x1, y1, x2, y2, TRUE, background,
  325.          foreground, title, 1, 0, 
  326.      shadow, 0, background, 1, BUT_CLOSE );
  327.       }
  328.    else
  329.       {
  330.       window = *i_window;
  331.       ui_rewindow( window, title );
  332.       }
  333.  
  334.    /* Write the text string to the box */
  335.  
  336.    ui_text( window->u_x1 + gr_strlen( "   " ),
  337.       window->u_y1 + ui_grwind->fysize,
  338.       window->u_x2, window->u_y2, 20, background, foreground, 
  339.       text );
  340.  
  341.    }
  342.  
  343. uid_capsule( x1, y1, x2, y2, color, style )
  344.    int x1, y1, x2, y2, color, style;
  345.    {
  346.    int r, x, y;
  347.  
  348.    x = x1;
  349.    r = ((( y2 - y1 ) * 30 ) / 60 );
  350.    y = y1 + r;
  351.    gr_circle( ui_screen, x, y, r, color, style );
  352.    x = x2;
  353.    gr_circle( ui_screen, x, y, r, color, style );
  354.    ui_fbox( x1, y1, x2, y2, color, style );
  355.    
  356.    }
  357.